#include <unordered_set>
using namespace std;
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

class FindElements {
public:
    unordered_set<int> vset;
    void dfs(TreeNode *root, int val) {
        if(root == nullptr) return ;
        root->val = val;
        vset.insert(val);
        if(root->left != nullptr) dfs(root->left, val*2+1);
        if(root->right != nullptr) dfs(root->right, val*2+2);
    }
    FindElements(TreeNode* root) {
        dfs(root, 0);
    }
    
    bool find(int target) {
        return vset.find(target) != vset.end();
    }
};